<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
	<meta http-equiv="Pragma" content="no-cache" />
	<meta http-equiv="Expires" content="0" />
    <title>我的订单</title>
    
    <link rel="stylesheet" type="text/css" href="../../css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/own.css"/>
	
	<style type="text/css">
    	.emptyAddress {
			text-align: center;
			margin-top: 50px;
			font-size: 0.9em;
			display:none;
		}
    </style>
   
</head>
<body>	
	<header class="mui-bar mui-bar-nav">
		<h4 style="margin-left: 5%; padding-top: 10px; color: #A9A9A9;">您的所有订单</h4>		
	</header>
	<div class="mui-content mui-scroll-wrapper own-content-padding" id="completeOrder">
		<div class="mui-scroll" style="top: 48px;">
			<ul  class="mui-table-view mui-table-view-chevron" id="order">
				
			</ul>
		</div>
		<div class="emptyAddress own-left-nav-color">
			<span>空空如也</span>
			<br />
			<span>你还没有下过订单哦</span>
			<br />
			<!--<button type="button" class="mui-btn">
				<span class="mui-icon iconfont icon-tianjia" style="padding: 0px 5px; color: gray;"></span>
			</button>-->
		
		</div>
	</div>
	<script type="text/javascript" src="../../js/jquery-1.11.1.min.js" ></script>
	<script src="../../js/mui.min.js" charset="UTF-8"></script>
	<script src="../../js/own.js" charset="UTF-8"></script>
	<script src="../../js/tool.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../js/simple.min.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript" src="../../js/url.js"></script>
	<script type="text/javascript" charset="UTF-8">
		var limit = 20;		//每一页多少条记录
		var offset = 0;		//从哪一条记录开始
		var num = 0;		//上拉刷新获取数据记录数
		
		mui.init({
			pullRefresh: {
				container: '#completeOrder',
				down: {
					callback: pulldownRefresh
				},
				up: {
					contentrefresh: '正在加载...',
					contentnomore:'没有更多数据了',
					callback: pullupRefresh
				}
			}
			
		});
		/**
		 * 下拉刷新具体业务实现
		 */
		function pulldownRefresh() {
			setTimeout(function() {
				//var oldnode = document.getElementById('order');
				//oldnode.parentNode.removeChild(oldnode);
				document.getElementById('order').innerHTML = "";
				search(sessionStorage.accountid,sessionStorage.token,limit,"0");
				mui('#completeOrder').pullRefresh().endPulldownToRefresh(); //refresh completed
			}, 1500);
		}
		var count = 0;
		/**
		 * 上拉加载具体业务实现
		 */
		function pullupRefresh() {
			setTimeout(function() {
				mui('#completeOrder').pullRefresh().endPullupToRefresh((num < limit )); //参数为true代表没有更多数据了。
				num = 0;
				search(sessionStorage.accountid,sessionStorage.token,limit,offset);
			}, 1500);
		}
		//mui.ready(function() {
			//mui('#completeOrder').pullRefresh().pullupLoading();
		//});
		
		
			//search(sessionStorage.accountid,sessionStorage.token,limit,"0");
			mui.ready(function() {
				mui('#completeOrder').pullRefresh().pullupLoading();
			});
		
		
		$(function(){
			
		});
	
		function getOpenId(){
			var url = getUrlArgObject();
			var requestUrl = "http://ixe.trasen.cn/rest/wxLogin";
			mui.ajax(requestUrl,{
				data:{
					wxCode:url.code
				},
				type:'post',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；
				crossDomain:true,  //强制使用5+跨域					
				success:function(data){
					//服务器返回响应，根据响应结果，分析是否登录成功；
					//alert(data);
					data = JSON.parse(data);					
					if(data.status == 0){
						sessionStorage.openId = data.openId;
						sessionStorage.token = data.token;
						sessionStorage.accountid = data.accountId;
						search(data.accountId,data.token,limit,"0");
					}else{
						alert("登录失败");
						//window.location.reload();
					}
				},
				error:function(xhr,type,errorThrown){
					//异常处理；
					console.log(type);
				}
			});
		}
		
		function search(accountId,tokenCode,limit,offset){
			var table = document.body.querySelector('.mui-table-view');
			var cells = document.body.querySelectorAll('.mui-table-view-cell');
			var data = {};
			data.accountId = accountId;
			data.tokenCode = tokenCode;
			data.serviceType = '0';					//0：被服务方,1：服务方（两个客户端参数约定）
			data.offset = offset;					//从哪一条记录开始
			data.limit = limit;						//每一页多少条记录
			data.isShopCart = "n";
			var requestUrl = "http://ixe.trasen.cn/rest/myOrder";
			mui.ajax(requestUrl,{
				data:data,
				type:'POST',						//HTTP请求类型
				timeout:10000,						//超时时间设置为10秒；
				crossDomain:true,  					//强制使用5+跨域					
				success:function(result){
					//返回json字符串，转成json对象进行属性获取
					//alert(result);
					result = JSON.parse(result);
					$("#resultCode").val(result.status);
					$("#resultMsg").val(result.msg);
					if(result.status != '0'){
						alert(result.msg );
					}else{
						var table = document.body.querySelector('.mui-table-view');
						//alert(JSON.stringify(result.data));
						for(var dataTable in result.data){  
							//alert(dataTable.length);
							num++;
							var li = document.createElement('li');
							li.className = 'mui-table-view-cell';
							li.style.paddingRight = "5px";
							
							//li.onclick = 'function(){alert(1);sessionStorage.orderDetails = JSON.stringify(result.data[dataTable]);window.location.href = "orderDetails.html";}';
							var tableStr = '<div class="mui-row" style="margin-top: 5px;">';
							tableStr += '<span class="mui-col-xs-5 serviceDate">'+result.data[dataTable].serviceDate+'</span>';
							tableStr += '<span class="mui-col-xs-4 productName" style="color: #04BB21;">'+result.data[dataTable].productName+'</span>';
							tableStr += '<span class="mui-col-xs-3 status">';
							if(result.data[dataTable].status == '预约中' && result.data[dataTable].paystatus == "n"){	
								tableStr += "待支付";
							}else{
								tableStr += result.data[dataTable].status;
							}
							tableStr += '</span></div>';
							tableStr += '<div class="mui-row" style="margin-top: 5px;">';
							tableStr += '<span class="mui-col-xs-1 mui-icon mui-icon-person"></span>';
							tableStr += '<span class="mui-col-xs-3 shipname">'+result.data[dataTable].shipname+'</span>';
							tableStr += '<span class="mui-col-xs-6 mui-icon mui-icon-phone Phone" style="font-size:16px"> '+result.data[dataTable].phone+' </span>';
							tableStr += '<span class="mui-col-xs-2 mui-icon mui-icon-arrowright"></span>';
							tableStr += '</div>';
							tableStr += '<div class="mui-row" style="margin-top: 5px;">';
							tableStr += '<span class="mui-col-xs-1 mui-icon mui-icon-location" ></span>';
							tableStr += '<span class="mui-col-xs-7 shipaddress"> '+result.data[dataTable].city+' '+result.data[dataTable].area+' '+result.data[dataTable].shipaddress+' </span>';
							tableStr += "<input type='hidden' class='dataList' value='"+JSON.stringify(result.data[dataTable])+"' />";
							tableStr += '</div>';
							li.innerHTML = tableStr;
							/*li.onclick = function(){
								alert(1);
								sessionStorage.orderDetails = JSON.stringify(result.data[dataTable]);
								window.location.href = "orderDetails.html";
								//document.getElementById("txt").value += newTp.value;
							}*/
							table.appendChild(li); 
							
						 }
						 mui('.mui-table-view').on('tap', '.mui-table-view-cell', function() {
							//var cell = this;							
							var dataList = $(this).children().children(".dataList").val();
							sessionStorage.orderDetails = dataList;
							//window.location.href = "orderDetails.html";

							mui.openWindow({
								url: 'orderDetails.html',
								id: 'orderDetails.html',
								/*extras: {
									serviceDate: serviceDate
								}*/
							});

						});
						/*var emptyAddress = document.querySelector('.emptyAddress');
						//判断如果没有可用地址就显示添加
						if (isEmpty(dataTable)) {
							emptyAddress.style.display = 'block';
						} else {
							emptyAddress.style.display = 'none';
						}*/
					}
				},
				error:function(xhr,type,errorThrown){
					//异常处理；
					console.log(type);
				}
				
			});
			offset = document.getElementById("order").getElementsByTagName('li').length;
			
		}
		
		
		
		
		
	</script>
	
</body>
</html>